import { getCounts } from 'src/api/reamtime.js';
import { getReamtimeList, } from 'src/api/reamtime.js'

const state = {
    isShowRightMenu: '',
    device: 'desktop',
    headSelectOptionValue: '',
    headReamtimeList: {},
    tabEatchLine: '',
    ztMinTime: '',
    ztMaxTime: '',
    levelList: {},
    statusId: {},
    timeInputContent: {},
    sBstatusId: '',
    resizeShow: null,
    alarmNum: 0,
}
const mutations = {
    SET_IS_SHOW_RIGHT_MENU: (state, isShowRightMenu) => {
        state.isShowRightMenu = isShowRightMenu
    },
    TOGGLE_DEVICE: (state, device) => {
        state.device = device
    },
    HEAD_SELECT_OPTION_VALUE: (state, headSelectOptionValue) => {
        state.headSelectOptionValue = headSelectOptionValue
    },
    HEAD_REAMTIME_LIST: (state, headReamtimeList) => {
        state.headReamtimeList = headReamtimeList
    },
    TAB_EATCH_LINE: (state, tabEatchLine) => {
        state.tabEatchLine = tabEatchLine
    },
    TIME_INPUT_CONTENT: (state, timeInputContent) => {
        state.timeInputContent = timeInputContent
    },
    ZT_MIN_TIME: (state, ztMinTime) => {
        state.ztMinTime = ztMinTime
    },
    ZT_MAX_TIME: (state, ztMaxTime) => {
        state.ztMaxTime = ztMaxTime
    },
    LEVEL_LIST: (state, levelList) => {
        state.levelList = levelList
    },
    STATUS_ID: (state, statusId) => {
        state.statusId = statusId
    },
    SB_STATUS_ID: (state, sBstatusId) => {
        state.sBstatusId = sBstatusId
    },
    RESIZE_SHOW: (state, resizeShow) => {
        state.resizeShow = resizeShow
    },
    ALARM_NUM: (state, alarmNum) => {
        state.alarmNum = alarmNum
    },
    MSG_NUM: (state, msgNum) => {
        state.msgNum = msgNum
    },
}

const actions = {
    toggleDevice({ commit }, device) {
        commit('TOGGLE_DEVICE', device)
    },
    alarm({ commit }, data) {
        return new Promise((resolve, reject) => {
            getCounts(data).then(res => {
                const { status, data } = res
                if (status == 200) {
                    commit('ALARM_NUM', data.alert_counts)
                    commit('MSG_NUM', data.msg_counts)
                }
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    conTent({ commit }, data) {
        return new Promise((resolve, reject) => {
            getReamtimeList(data).then(res => {
                const { status, data } = res
                if (status == 200) {
                    commit('HEAD_REAMTIME_LIST', res);
                }
                resolve(data)
            }).catch(error => {
                commit('HEAD_REAMTIME_LIST', []);
                reject(error)
            })
        })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}